﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SqlServer.Management.Smo;

namespace T4Common
{
    public static class CommonUtility
    {
        public static string GetDataClassName(string format, string tableName)
        {
            return String.Format(format, tableName.Substring(0, 1).ToUpper() + tableName.Substring(1));
        }

        public static string GetBusinessClassName(string format, string tableName)
        {
            return String.Format(format, tableName.Substring(0, 1).ToUpper() + tableName.Substring(1));
        }

        public static string GetEntityClassName(string format, string tableName)
        {
            return String.Format(format, tableName.Substring(0, 1).ToUpper() + tableName.Substring(1));
        }

        public static string GetPropertyName(Column column)
        {
            return column.Name.Substring(0, 1).ToUpper() + column.Name.Substring(1);
        }

        public static string GetPropertyName(string columnName)
        {
            return columnName.Substring(0, 1).ToUpper() + columnName.Substring(1);
        }

        public static string GetCSharpParamterType(DataType dataType)
        {
            throw new Exception("null");
            return null;
        }
        public static string GetCSharpVariableType(DataType dataType)
        {
            var currentDType = System.Data.SqlDbType.NVarChar;
            Enum.TryParse(dataType.SqlDataType.ToString(), out currentDType);
            switch (currentDType)
            {
                case System.Data.SqlDbType.BigInt:
                    return "long";
                    break;
                case System.Data.SqlDbType.Bit:
                    return "byte";
                    break;
                case System.Data.SqlDbType.Float:
                    return "float";
                    break;
                case System.Data.SqlDbType.Int:
                    return "int";
                    break;
                case System.Data.SqlDbType.Money:
                    return "decimal";
                    break;
                case System.Data.SqlDbType.Real:
                    return "float";
                    break;
                case System.Data.SqlDbType.SmallInt:
                    return "int";
                    break;
                case System.Data.SqlDbType.SmallMoney:
                    return "decimal";
                    break;
                case System.Data.SqlDbType.TinyInt:
                    return "byte";
                    break;
                case System.Data.SqlDbType.Decimal:
                    return "decimal";
                    break;
                case System.Data.SqlDbType.Char:
                    return "string";
                    break;
                case System.Data.SqlDbType.NChar:
                    return "string";
                    break;
                case System.Data.SqlDbType.NText:
                    return "string";
                    break;
                case System.Data.SqlDbType.NVarChar:
                    return "string";
                    break;
                case System.Data.SqlDbType.Text:
                    return "string";
                    break;
                case System.Data.SqlDbType.UniqueIdentifier:
                    return "Guid";
                    break;
                case System.Data.SqlDbType.VarChar:
                    return "string";
                    break;
                case System.Data.SqlDbType.Date:
                    return "DateTime";
                    break;
                case System.Data.SqlDbType.DateTime:
                    return "DateTime";
                    break;
                case System.Data.SqlDbType.DateTime2:
                    return "DateTime";
                    break;
                case System.Data.SqlDbType.DateTimeOffset:
                    return "DateTime";
                    break;
                case System.Data.SqlDbType.SmallDateTime:
                    return "DateTime";
                    break;
                case System.Data.SqlDbType.Time:
                    return "DateTime";
                    break;
                default:
                    return "string";
            }


        }
    }
}
